/**
 * 写一个泛型类，泛型类中有一个方法，求一个数组当中的最大值
 */
class Alg<T extends Comparable<T>>{//泛型类
    public T findMax(T[] array){
        T max = array[0];//max是Object类型，向上转型
        for (int i = 1; i < array.length; i++) {
            /*if(max < array[i]){//Object类型是引用类型，引用类型不能用><比较
                max = array[i];
            }*/
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }

        }
        return max;
    }
}
class Person implements Comparable<Person>{
    public int age;

    public Person(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Person o) {
        return this.age-o.age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        Alg<Person> alg = new Alg<>();
        Person[] people = {new Person(10),new Person(20)};
        Person person = alg.findMax(people);
        System.out.println(person);
    }
    public static void main1(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,2,3,4};
        Integer ret = alg.findMax(array);
        System.out.println(ret);
    }
}

